package com.hk.service.order.impl;

import org.springframework.stereotype.Service;

import com.hk.commons.HqlFilter;
import com.hk.commons.LongId;
import com.hk.commons.entity.order.OrderInfo;
import com.hk.commons.entity.order.OrderRouteInfo;
import com.hk.dao.base.impl.BaseServiceImpl;
import com.hk.service.order.IOrderRouteInfo;

@Service
public class OrderRouteInfoImpl extends BaseServiceImpl<OrderRouteInfo>
		implements IOrderRouteInfo {

	@Override
	public OrderRouteInfo findById(long id) {

		return getById(id);
	}

	@Override
	public Long add(OrderRouteInfo model) {

		Long id = LongId.get();
		model.setId(id);

		model.setCts(System.currentTimeMillis());

		super.save(model);

		return id;
	}
	
	@Override
	public Long addByOrder(OrderInfo  order) {
		
		OrderRouteInfo routeInfo = new OrderRouteInfo();
		Long id = LongId.get();
		routeInfo.setId(id);
		routeInfo.setUserId(order.getUserId());
		routeInfo.setCts(order.getOrderCreatedOn());
		routeInfo.setOrderId(order.getId());
		routeInfo.setFinancialPlannerId(order.getFinancialPlannerId());
		routeInfo.setProductId(order.getProductId());
		routeInfo.setBrokerOrderNo(order.getBrokerOrderNo());
		routeInfo.setStatus(order.getPayStatus());
		routeInfo.setCompanyId(order.getCompanyId());
		super.save(routeInfo);

		return id;
	}
	
	
	@Override
	public OrderRouteInfo findByOrderId(long orderId) {
		HqlFilter hqlFilter = new HqlFilter();
		hqlFilter.addEQFilter("orderId", orderId);
		OrderRouteInfo routeInfo = getByFilter(hqlFilter);
		
		return routeInfo;
	}

}
